package com.aw.guiguzi.bean

import com.aw.baselib.util.AwConvertUtil
import com.aw.baselib.util.AwDataUtil
import com.aw.guiguzi.enums.TrendTagEnums

class CalSuggestItemBean {
    var tag: String
    var type: String
    var name: String? = null
    var value: String? = null
    var strValue: String? = null
    var typeNameJump: String? = null //类型 如跳
    var typeNameSort: String? = null //类型 如顺
    var countAllTypeJump = 0 //所有数字 跳 数量统计
    var countPre15Type1 = 0 //所有数字 前15位 数量统计
    var countPreTypeJump = 0 //跳 筛除前15位统计
    var limitCountAllTypeJump = 0 //跳 限制总数量统计
    var limitCountTypeJump = 0 //跳 限制数量统计
    var countAllTypeSort = 0 //所有数字 顺 数量统计
    var countPre15Type2 = 0 //所有数字 前15位 数量统计
    var countPreTypeSort = 0 //顺 筛除前15位统计
    var limitCountAllTypeSort = 0 //顺 限制总数量统计
    var limitCountTypeSort = 0 //顺 限制数量统计
    var isEnable = false
    var isSuggestItem = false

    constructor(tag: String, type: String, name: String?, value: String?, isSuggestItem: Boolean) {
        this.tag = tag
        this.type = type
        this.name = name
        this.value = value
        this.isSuggestItem = isSuggestItem
    }

    constructor(tag: String, type: String, name: String?, value: String?) {
        this.tag = tag
        this.type = type
        this.name = name
        this.value = value
    }

    constructor(tag: String, type: String, name: String?) {
        this.tag = tag
        this.type = type
        this.name = name
        value = value
    }

    constructor(enums: TrendTagEnums, isEnable: Boolean) {
        tag = enums.code
        type = enums.type
        name = enums.desc
        this.isEnable = isEnable
    }

    constructor(tag: String, type: String, isEnable: Boolean) {
        this.tag = tag
        this.type = type
        this.isEnable = isEnable
    }

    private fun handleResult(param: String): String {
        var param = param
        if (AwDataUtil.isEmpty(param)) {
            return "--"
        }
        if (param.contains("0.")) { //0.8
            param = param.replace("0.", "")
        }
        if (param.length == 1) { //0.8 ==> 8
            param = param + "0"
        } else if (param.startsWith("0")) { //0.08 ==> 08
            param = param.split("".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1]
        }
        if (param.contains(".0")) { //1.0
            param = param.replace(".0", "00")
        }
        return param
    }

    val rateAll: String
        get() = if (countAllTypeJump + countAllTypeSort <= 0) {
            "--"
        } else handleResult(
            AwConvertUtil.div(
                countAllTypeJump.toDouble(),
                (countAllTypeJump + countAllTypeSort).toDouble(),
                2
            ).toString()
        )

    //        return AwConvertUtil.div(getCountAllTypeJump(), getCountAllTypeJump() + getCountAllTypeSort());
    val pre15Rate: String
        get() = if (countPre15Type1 + countPre15Type2 <= 0) {
            "--"
        } else handleResult(
            AwConvertUtil.div(
                countPre15Type1.toDouble(),
                (countPre15Type1 + countPre15Type2).toDouble(),
                2
            ).toString()
        )
    val rateOutPre: String
        get() = if (countPreTypeJump + countPreTypeSort <= 0) {
            "--"
        } else handleResult(
            AwConvertUtil.div(
                countPreTypeJump.toDouble(),
                (countPreTypeJump + countPreTypeSort).toDouble(),
                2
            ).toString()
        )

    //        return AwConvertUtil.div(getCountPreTypeJump(), getCountPreTypeJump() + getCountPreTypeSort());
    val rateLimitAll: String
        get() = if (limitCountAllTypeJump + limitCountAllTypeSort <= 0) {
            "--"
        } else handleResult(
            AwConvertUtil.div(
                limitCountAllTypeJump.toDouble(),
                (limitCountAllTypeJump + limitCountAllTypeSort).toDouble(),
                2
            ).toString()
        )

    //        return AwConvertUtil.div(getLimitCountAllTypeJump(), getLimitCountAllTypeJump() + getLimitCountAllTypeSort());
    val rateLimit: String
        get() = if (limitCountTypeJump + limitCountTypeSort <= 0) {
            "--"
        } else handleResult(
            AwConvertUtil.div(
                limitCountTypeJump.toDouble(),
                (limitCountTypeJump + limitCountTypeSort).toDouble(),
                2
            ).toString()
        )

    //        return AwConvertUtil.div(getLimitCountTypeJump(), getLimitCountTypeJump() + getLimitCountTypeSort());
    fun getResultCount(param: Int): String {
        return if (param == 0) {
            "--"
        } else param.toString()
    }
}